package br.inf.solutions.apresentacoes.ssp.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import br.com.vexillum.model.CommonEntityActivated;
import br.com.vexillum.model.annotations.Validate;
import br.com.vexillum.model.annotations.ValidatorClass;
import br.inf.solutions.apresentacoes.ssp.model.basics.Reason;

@SuppressWarnings("serial")
@ValidatorClass(validatorClass = "br.inf.solutions.apresentacoes.ssp.control.validator.ReasonTransferReserveValidator")
@Entity
@Table(name = "reasontransferreserve")
public class ReasonTransferReserve extends CommonEntityActivated {
	
	public ReasonTransferReserve() {
		squarePostReason = new ArrayList<>();
	}
	
	@Validate(notNull=true)
	@ManyToOne(fetch= FetchType.LAZY)
	@JoinColumn(name="reason",nullable=false, insertable=true, updatable=true, unique=false)
	private Reason reason;
	
	@Validate(notNull=true)
	@Column(name="lawreason", insertable=true, updatable=true, unique=false)
	private String lawReason;
	
	@Validate(notNull=true)
	@Column(name="initialDateLaw", insertable=true, updatable=true, unique=false)
	private Date initialDateLaw;
	
	@Column(name="finalDateLaw", insertable=true, updatable=true, unique=false)
	private Date finalDateLaw;

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "reasontransferreserve", targetEntity = SquarePostReason.class, orphanRemoval = true)
	@Cascade(value = CascadeType.ALL)
	private List<SquarePostReason> squarePostReason;

	public Reason getReason() {
		return reason;
	}

	public void setReason(Reason reason) {
		this.reason = reason;
	}

	public String getLawReason() {
		return lawReason;
	}

	public void setLawReason(String lawReason) {
		this.lawReason = lawReason;
	}

	public Date getInitialDateLaw() {
		return initialDateLaw;
	}

	public void setInitialDateLaw(Date initialDateLaw) {
		this.initialDateLaw = initialDateLaw;
	}

	public Date getFinalDateLaw() {
		return finalDateLaw;
	}

	public void setFinalDateLaw(Date finalDateLaw) {
		this.finalDateLaw = finalDateLaw;
	}

	public List<SquarePostReason> getSquarePostReason() {
		return squarePostReason;
	}

	public void setSquarePostReason(List<SquarePostReason> squarePostReason) {
		this.squarePostReason = squarePostReason;
	}
	
	@Override
	public String toString() {
		if(reason == null)
			return "";
		return reason.getName();
	}
}
